<?php


namespace app\cms\admin\controller\saas;

use app\cms\authCallBack\saas;
use app\cms\community\lib\saas\initializationSaas;
use app\cms\dto\saas\saasClientInfo;
use app\cms\model\saas\saasClientModel;
use iflow\auth\Authorize\AuthAnnotation;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\{ PostMapping, GetMapping };


#[Controller('%cmsAdmin%/saas')]
class saasController
{
    /**
     * 创建Saas服务
     * @param saasClientInfo $saasClientInfo
     * @return Response
     */
    #[PostMapping]
    #[AuthAnnotation('saasAdmin', 'saasAccountWrite|saasAccountReadWrite', saas::class . '@validIsSaasAccountValidServer')]
    public function createSaasAccount(saasClientInfo $saasClientInfo): Response
    {
        return (new initializationSaas(
            $saasClientInfo -> server_db_id, $saasClientInfo -> server_id,
        )) -> initialization($saasClientInfo);
    }

    /**
     * 获取Saas服务 客户列表
     * @param string $saas_domain
     * @param string $saas_as_domain
     * @param int $uid
     * @param int $status
     * @return Response
     */
    #[GetMapping]
    #[AuthAnnotation('saasAdmin', 'saasAccountRead|saasAccountReadWrite', saas::class . '@validIsSaasAccountValidServer')]
    public function getSaasAccountList(
        string $saas_domain = '',
        string $saas_as_domain = '',
        int $uid = 0,
        int $status = -1
    ): Response {
        return (new saasClientModel()) -> getSaasClientList(
            $saas_domain, $saas_as_domain, $uid, $status
        );
    }
}